package com.yulongtian.offers.day202211.day20221108;

import java.util.Arrays;

/**
 * https://leetcode.cn/problems/bu-ke-pai-zhong-de-shun-zi-lcof/?favorite=xb9nqhhg
 * 可
 *
 * @author yulongTian
 * @create 2022-11-08 10:09
 */
public class Test01 {
    public static void main(String[] args) {
        int[] nums = {0, 0, 1, 2, 5};
        System.out.println(isStraight(nums));
    }

    public static boolean isStraight(int[] nums) {
        Arrays.sort(nums);
        //0的个数
        int zero_num = 0;
        //顺子起始数字
        int start_num = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                zero_num++;
            }
        }
        start_num = nums[zero_num];

        for (int i = zero_num; i < nums.length; i++) {
            if (nums[i] == start_num) {
                start_num++;
                continue;
            } else {
                if (zero_num > 0) {
                    zero_num--;
                    start_num++;
                    i--;
                } else {
                    return false;
                }

            }
        }
        return true;
    }


}
